var lz_title_timer;
var lz_title_step = 0;
var lz_title_modes = new Array(document.title,"<!--lang_client_new_messages-->");
var lz_standard_title = document.title;
var lz_document_head = document.getElementsByTagName("head")[0];
var lz_geo_resolution;
var lz_geo_resolution_needed = false;

if(typeof(encodeURIComponent) == 'undefined')
{
	encodeURIComponent = function(uri)
	{
		return (escape(uri));
	}
}

function lz_array_indexOf(_hsa,_needle)
{
    for(var i=0; i<_hsa.length; i++)
        if(_hsa[i]==_needle)
            return i;
    return -1;
}

function lz_jssess()
{	
	this.Save = lz_jssess_save;
	this.Load = lz_jssess_load;
	
	this.DelimiterStart = "LZSDS";
	this.DelimiterEnd = "LZSDE";

	this.GeoResolutions = 0;
	this.GeoResolved = Array();
	this.BrowserId = "f82a2f2c1b";
	this.UserId = "4ead54093c";
	this.ServerId = "b52a3";

	function lz_jssess_save()
	{
		var data = this.DelimiterStart + lz_global_base64_url_encode(this.BrowserId + ";" + this.UserId + ";" + this.GeoResolved  + ";" + this.GeoResolutions+ ";" + this.ServerId + ";") + this.DelimiterEnd;
		if(window.name == null || window.name == "undefinded" || window.name  == "" || (window.name == null && window.name.indexOf(this.DelimiterStart) == -1))
		{
			if(window.name == null || window.name == "undefinded" || window.name  == "")
				window.name = data;
			else
				window.name += data;
		}
		else
		{
			var regex = new RegExp(/\LZSDS.*?LZSDE/g);
			window.name = window.name.replace(regex,"");
			window.name += data;
		}
	}
	
	function lz_jssess_load()
	{
		var data = window.name;
		if(data.indexOf(this.DelimiterStart) != -1)
		{
			data = lz_global_base64_url_decode(data.split(this.DelimiterStart)[1].split(this.DelimiterEnd)[0]).split(";");
			if(this.ServerId == data[4])
			{
				this.BrowserId = data[0];
				this.UserId = data[1];
				this.GeoResolved = data[2].split(",");
				this.GeoResolutions = data[3];
			}
		}
	}
}

function lz_chat_window()
{
	this.BrowserId = "";
	this.LastActive = 0;
	this.Closed = false;
	this.Deleted = false;
}

function lz_geo_resolver()
{
	this.ResolveAsync = lz_resolver_connect_async;
	this.TimeoutConnection = lz_resolver_timeout_connection;
	this.SetStatus = lz_resolver_set_status;
	this.SetSpan = lz_resolver_set_span;
	this.Status = 0;
	this.Span = 0;
	
	this.OnEndEvent;
	this.OnTimeoutEvent;	
	this.OnSpanEvent;	
	
	var OnEnd;
	var OnTimeout;
	var OnSpan;

	var lz_resolver_request;
	var lz_resolver_timeout_timer;
	
	function lz_resolver_connect_async()
	{
		OnEnd = this.OnEndEvent;
		OnTimeout = this.OnTimeoutEvent;
		OnSpan = this.OnSpanEvent;
		
		lz_resolver_timeout_timer = setTimeout(this.TimeoutConnection,15000);
		lz_resolver_request = document.createElement("script");
		lz_resolver_request.id = "livezilla_geoscript";
		
		var oak = '';
		
		

		lz_resolver_request.src = "http://ssl.livezilla.net/geo/resolute/?aid=&dbp=0&gv=1021&method=" + OnEnd + "&spanm=" + OnSpan + "&oak=" + oak;
		lz_document_head.appendChild(lz_resolver_request);
	}

	function lz_resolver_timeout_connection()
	{
		if(OnTimeout != null)
			OnTimeout();
	}
	
	function lz_resolver_set_status(_status)
	{
		this.Status = _status;
	}
	
	function lz_resolver_set_span(_span)
	{
		this.Span = _span;
	}
}

function lz_global_replace_breaks(_text)
{
	_text = _text.replace(/[\r\n]+/g, "<br>");
	return _text.replace(/[\t]+/g, "&nbsp;&nbsp;&nbsp;");
}

function lz_global_base64_url_encode(_text)
{
	if(_text.length == 0)
		return "";

	_text = lz_global_base64_encode(lz_global_utf8_encode(_text.toString()));
	_text = _text.replace(/=/g, "_");
	_text = _text.replace(/\+/g, "-");
	_text = _text.replace(/\//g, ",");
	return _text;
}

function lz_global_base64_url_decode(_text)
{
	if(!(_text != null && _text.length > 0))
		return "";
		
	_text = _text.replace("_","=");
	_text = _text.replace("-","+");
	_text = _text.replace(",","/");
	_text = lz_global_utf8_decode(lz_global_base64_decode(_text));
	return _text;
}
	
function lz_global_base64_decode(_text)
{
	var base64_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
	var bits;
	var decOut = '';
	var i = 0;
	for(; i<_text.length; i += 4)
	{
		bits = (base64_chars.indexOf(_text.charAt(i)) & 0xff) <<18 |
		(base64_chars.indexOf(_text.charAt(i +1)) & 0xff) <<12 |
		(base64_chars.indexOf(_text.charAt(i +2)) & 0xff) << 6 |
		base64_chars.indexOf(_text.charAt(i +3)) & 0xff;
		decOut += String.fromCharCode((bits & 0xff0000) >>16, (bits & 0xff00) >>8, bits & 0xff);
	}
	if(_text.charCodeAt(i -2) == 61)
		return(decOut.substring(0, decOut.length -2));
	else if(_text.charCodeAt(i -1) == 61)
		return(decOut.substring(0, decOut.length -1));
	else 
		return(decOut);
}

function lz_global_base64_encode(_input) 
{
	var base64_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
   	var output = "";
   	var chr1, chr2, chr3;
   	var enc1, enc2, enc3, enc4;
	var i = 0;
	
	do 
	{
	   chr1 = _input.charCodeAt(i++);
	   chr2 = _input.charCodeAt(i++);
	   chr3 = _input.charCodeAt(i++);
	
	   enc1 = chr1 >> 2;
	   enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	   enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	   enc4 = chr3 & 63;
	
	   if (isNaN(chr2)) 
	      enc3 = enc4 = 64;
	   else if (isNaN(chr3)) 
	      enc4 = 64;
	
	   output = output + base64_chars.charAt(enc1) + base64_chars.charAt(enc2) +
	      base64_chars.charAt(enc3) + base64_chars.charAt(enc4);
	} 
	while (i < _input.length);
	return output;
}

function lz_global_utf8_encode(_string,_encodeuri) 
{
	_string = _string.replace(/\r\n/g,"\n");
	var utftext = "";
	for (var n = 0; n < _string.length; n++) 
	{
	    var c = _string.charCodeAt(n);
	    if (c < 128) 
		{
	        utftext += String.fromCharCode(c);
	    }
	    else if((c > 127) && (c < 2048)) 
		{
	        utftext += String.fromCharCode((c >> 6) | 192);
	        utftext += String.fromCharCode((c & 63) | 128);
	    }
	    else 
		{
	        utftext += String.fromCharCode((c >> 12) | 224);
	        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
	        utftext += String.fromCharCode((c & 63) | 128);
	    }
	}
	if(_encodeuri)
		return encodeURIComponent(utftext);
	else
		return utftext;
}

function lz_global_utf8_decode(utftext) 
{
	var string = "";
    var i = 0;
	var c, c1, c2
    c = c1 = c2 = 0;

    while ( i < utftext.length ) 
	{
        c = utftext.charCodeAt(i);
        if (c < 128) 
		{
            string += String.fromCharCode(c);
            i++;
        }
        else if((c > 191) && (c < 224)) 
		{
            c2 = utftext.charCodeAt(i+1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        }
        else 
		{
            c2 = utftext.charCodeAt(i+1);
            c3 = utftext.charCodeAt(i+2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    return string;
}

function lz_set_title_mode()
{
    document.title = lz_title_modes[lz_title_step++ % 2];
}

function lz_switch_title_mode(_active)
{
	if(_active)
	{
		if(lz_title_timer == null)
    		lz_title_timer = setInterval("lz_set_title_mode()",800);
	}
	else
	{
		clearInterval(lz_title_timer);
		lz_title_timer = null;
   		document.title = lz_standard_title;
		lz_title_step = 0;
	}
}

function lz_global_replace_smilies(_text)
{
	var shorts = new Array(/:-\)/g,/::smile/g,/:\)/g,/:-\(/g,/::sad/g,/:\(/g,/:-]/g,/::lol/g,/;-\)/g,/::wink/g,/;\)/g,/:'-\(/g,/::cry/g,/:-O/g,/::shocked/g,/:-\\\\/g,/::sick/g,/:-p/g,/::tongue/g,/:-P/g,/:\?/g,/::question/g,/8-\)/g,/::cool/g,/zzZZ/g,/::sleep/g,/:-\|/g,/::neutral/g);
	var images = new Array("smile","smile","smile","sad","sad","sad","lol","lol","wink","wink","wink","cry","cry","shocked","shocked","sick","sick","tongue","tongue","tongue","question","question","cool","cool","sleep","sleep","neutral","neutral");
	for(var i = 0;i<shorts.length;i++)
		_text = _text.replace(shorts[i]," <img border=0 src='./images/smilies/"+images[i]+".gif'> ");
	return _text;
}

function lz_global_replacements(_text,_smileys)
{
	_text = _text.replace(/\\'/g,"'");
	_text = _text.replace(/\"/g,"\"");
	if(_smileys)
		_text = lz_global_replace_smilies(_text);
	return _text;
}

function lz_global_timestamp()
{
	var now = new Date();
	var ts = Math.round((now.getTime()/1000));
	return (ts);
}

function lz_global_microstamp()
{
	var now = new Date();
	var ts = now.getTime();
	return (ts);
}

function lz_global_get_long_poll_runtime()
{
	if(lz_chat_data.LastConnectionFailed)
		return 20;
	var value = lz_chat_data.PollTimeout - lz_chat_data.ChatFrequency - 25;
	if(value >= 60)
		value = 65;
	return value;
}

function lz_chat_get_locale_time()
{
	var time = new Date().toLocaleTimeString()
	time = time.split(" (");
	return time[0];
}

function lz_chat_get_locale_date()
{
	var date = new Date().toLocaleString();
	date = date.split(" (");
	return date[0];
}

function lz_global_handle_exception(exception,file,line)
{
	//alert(exception);
	return true;
}

function lz_global_trim(_str) 
{
	return _str.replace(/^\s+|\s+$/g,"");
}

function lz_global_get_entities() 
{
	var map = new Array(), symbol = '',entities = new Array();
	entities['34'] = '&quot;';
	entities['39'] = '&#39;';
    entities['38'] = '&amp;';
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';
	entities['160'] = '&nbsp;';
	entities['161'] = '&iexcl;';
	entities['162'] = '&cent;';
	entities['163'] = '&pound;';
	entities['164'] = '&curren;';
	entities['165'] = '&yen;';
	entities['166'] = '&brvbar;';
	entities['167'] = '&sect;';
	entities['168'] = '&uml;';
	entities['169'] = '&copy;';
	entities['170'] = '&ordf;';
	entities['171'] = '&laquo;';
	entities['172'] = '&not;';
	entities['173'] = '&shy;';
	entities['174'] = '&reg;';
	entities['175'] = '&macr;';
	entities['176'] = '&deg;';
	entities['177'] = '&plusmn;';
	entities['178'] = '&sup2;';
	entities['179'] = '&sup3;';
	entities['180'] = '&acute;';
	entities['181'] = '&micro;';
	entities['182'] = '&para;';
	entities['183'] = '&middot;';
	entities['184'] = '&cedil;';
	entities['185'] = '&sup1;';
	entities['186'] = '&ordm;';
	entities['187'] = '&raquo;';
	entities['188'] = '&frac14;';
	entities['189'] = '&frac12;';
	entities['190'] = '&frac34;';
	entities['191'] = '&iquest;';
	entities['192'] = '&Agrave;';
	entities['193'] = '&Aacute;';
	entities['194'] = '&Acirc;';
	entities['195'] = '&Atilde;';
	entities['196'] = '&Auml;';
	entities['197'] = '&Aring;';
	entities['198'] = '&AElig;';
	entities['199'] = '&Ccedil;';
	entities['200'] = '&Egrave;';
	entities['201'] = '&Eacute;';
	entities['202'] = '&Ecirc;';
	entities['203'] = '&Euml;';
	entities['204'] = '&Igrave;';
	entities['205'] = '&Iacute;';
	entities['206'] = '&Icirc;';
	entities['207'] = '&Iuml;';
	entities['208'] = '&ETH;';
	entities['209'] = '&Ntilde;';
	entities['210'] = '&Ograve;';
	entities['211'] = '&Oacute;';
	entities['212'] = '&Ocirc;';
	entities['213'] = '&Otilde;';
	entities['214'] = '&Ouml;';
	entities['215'] = '&times;';
	entities['216'] = '&Oslash;';
	entities['217'] = '&Ugrave;';
	entities['218'] = '&Uacute;';
	entities['219'] = '&Ucirc;';
	entities['220'] = '&Uuml;';
	entities['221'] = '&Yacute;';
	entities['222'] = '&THORN;';
	entities['223'] = '&szlig;';
	entities['224'] = '&agrave;';
	entities['225'] = '&aacute;';
	entities['226'] = '&acirc;';
	entities['227'] = '&atilde;';
	entities['228'] = '&auml;';
	entities['229'] = '&aring;';
	entities['230'] = '&aelig;';
	entities['231'] = '&ccedil;';
	entities['232'] = '&egrave;';
	entities['233'] = '&eacute;';
	entities['234'] = '&ecirc;';
	entities['235'] = '&euml;';
	entities['236'] = '&igrave;';
	entities['237'] = '&iacute;';
	entities['238'] = '&icirc;';
	entities['239'] = '&iuml;';
	entities['240'] = '&eth;';
	entities['241'] = '&ntilde;';
	entities['242'] = '&ograve;';
	entities['243'] = '&oacute;';
	entities['244'] = '&ocirc;';
	entities['245'] = '&otilde;';
	entities['246'] = '&ouml;';
	entities['247'] = '&divide;';
	entities['248'] = '&oslash;';
	entities['249'] = '&ugrave;';
	entities['250'] = '&uacute;';
	entities['251'] = '&ucirc;';
	entities['252'] = '&uuml;';
	entities['253'] = '&yacute;';
	entities['254'] = '&thorn;';
	entities['255'] = '&yuml;';
	
	for (key in entities) 
	{
        var symbol = String.fromCharCode(key);
        map[symbol] = entities[key];
	}
    return map;
}

function lz_global_htmlentities(_value) 
{
	var entities = lz_global_get_entities();
	var key = '',entity = '';
    for (key in entities) 
	{
 		entity = entities[key];
        _value = _value.split(key).join(entity);
    }
    return _value;
}

function lz_global_get_page_offset_y()
{
	if(window.pageYOffset != null)
		return window.pageYOffset;
	else
		return Math.max(document.documentElement.scrollTop, document.body.scrollTop);
}

function lz_global_get_page_offset_x()
{
	if(window.pageXOffset != null)
		return window.pageXOffset;
	else
		return Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
}

function lz_global_is_xhtml()
{
	var result=false;
	var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
	if(typeof document.namespaces != "undefined")
		result=document.all[0].nodeType==8 ? re.test(document.all[0].nodeValue) : false;
	else
		result=document.doctype != null ? re.test(document.doctype.publicId) : false;
	if(result)
		return (RegExp.$1=="XHTML")
	return false;
}
window.onerror=lz_global_handle_exception;

if(document.getElementById('livezilla_style') == null)
{
	var lz_poll_id = 0;
	var lz_poll_url = "http://www.tmdhosting.com/chat/server.php";
	var lz_poll_frequency = 10;
	var lz_referrer = document.referrer;
	var lz_stopped = false;
	var lz_request_window = null;
	var lz_alert_window = null;
	var lz_request_active = null;
	var lz_alert_active = null;
	var lz_website_push_active = null;
	var lz_session;
	var lz_style = document.createElement('LINK');
	var lz_area_code = "";
	var lz_user_name = "";
	var lz_user_email = "";
	var lz_user_company = "";
	var lz_user_question = "";
	var lz_user_customs = new Array('','','','','','','','','','');
	var lz_timer = null;
	var lz_timezone_offset = (new Date().getTimezoneOffset() / 60) * -1;
	var lz_geo_data_count = 6;
	var lz_alert_html = 'PGRpdiBpZD0ibHpfY2hhdF9hbGVydF9ib3giPg0KCTx0YWJsZSBjZWxsc3BhY2luZz0iNCIgY2VsbHBhZGRpbmc9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9Ijk1JSI+DQoJCTx0cj4NCgkJCTx0ZCBoZWlnaHQ9IjE1IiB2YWxpZ249InRvcCIgaWQ9Imx6X2NoYXRfYWxlcnRfYm94X3RpdGxlIiBjb2xzcGFuPSIyIj5UTURIb3N0aW5nIFNhbGVzIExpdmVjaGF0PC90ZD4NCgkJPC90cj4NCgkJPHRyPg0KCQkJPHRkIHdpZHRoPSI1MCIgYWxpZ249ImNlbnRlciIgdmFsaWduPSJ0b3AiPjxpbWcgc3JjPSJodHRwOi8vd3d3LnRtZGhvc3RpbmcuY29tL2NoYXQvaW1hZ2VzL2ljb25faW5mby5naWYiIGFsdD0iIiB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIGJvcmRlcj0iMCIgc3R5bGU9Im1hcmdpbjoxMHB4OyI+PC90ZD4NCgkJCTx0ZCBpZD0ibHpfY2hhdF9hbGVydF9ib3hfdGV4dCI+PC90ZD4NCgkJPC90cj4NCgkJPHRyPg0KCQkJPHRkIGhlaWdodD0iMzAiIHZhbGlnbj0idG9wIiBhbGlnbj0iY2VudGVyIiBjb2xzcGFuPSIyIj48aW5wdXQgdHlwZT0iYnV0dG9uIiBpZD0ibHpfY2hhdF9hbGVydF9idXR0b24iIHZhbHVlPSJPSyI+PC90ZD4NCgkJPC90cj4NCgk8L3RhYmxlPg0KPC9kaXY+DQoNCg0K';
	var lz_geo_resolution = new lz_geo_resolver();
	var lz_chat_windows = new Array();
	var lz_check_cw = null;
	
	lz_tracking_load_style();
	lz_tracking_start_system();
}

function lz_is_geo_resolution_needed()
{
	return (lz_geo_resolution_needed && lz_session.GeoResolved.length != 7 && lz_session.GeoResolutions < 5);
}

function lz_tracking_remove_chat_window(_browserId)
{
	try
	{
		for(var browser in lz_chat_windows)
		{
			if(lz_chat_windows[browser].BrowserId == _browserId)
			{
				lz_chat_windows[browser].Deleted =
				lz_chat_windows[browser].Closed = true;
			}
		}
	}
	catch(ex)
	{
	  // domain restriction
	}
}

function lz_tracking_add_chat_window(_browserId,_parent)
{
	var bfound, bdelete, bactive = false;
	for(var browser in lz_chat_windows)
	{
		if(lz_chat_windows[browser].BrowserId == _browserId || _parent)
		{
			if(!_parent)
			{
				lz_chat_windows[browser].LastActive = lz_global_timestamp();
				lz_chat_windows[browser].Deleted = false;
				lz_chat_windows[browser].Closed = false;
			}
			else if(!lz_chat_windows[browser].Deleted && !lz_chat_windows[browser].Closed && (lz_chat_windows[browser].LastActive <= (lz_global_timestamp()-4)))
			{
				lz_chat_windows[browser].Closed = true;
				bdelete = true;
			}
			bfound = true;
		}
		
		if(!lz_chat_windows[browser].Closed)
			bactive = true;
	}
	if(!bfound && !_parent)
	{
		var chatWindow = new lz_chat_window();
		chatWindow.BrowserId = _browserId;
		chatWindow.LastActive = lz_global_timestamp();
		lz_chat_windows.push(chatWindow);
		bactive = true;
	}
	else if(_parent && bdelete)
	{
		lz_tracking_poll_server();
	}

	if(bactive && lz_check_cw == null)
		lz_check_cw = setTimeout("lz_check_cw=null;lz_tracking_add_chat_window('"+_browserId+"',true);",2000);
}

function lz_tracking_load_style()
{
	lz_style.id = "livezilla_style";
	lz_style.href = "http://www.tmdhosting.com/chat/templates/style.css";
	lz_style.rel = 'stylesheet';
	lz_style.type = 'text/css';
	lz_document_head.appendChild(lz_style);
}

function lz_tracking_start_system()
{
	if(location.search.indexOf("lzcobrowse") != -1)
		return;
		
	lz_session = new lz_jssess();
	lz_session.Load();
	
	try
	{
		if(window.opener != null && typeof(window.opener.lz_get_session) != 'undefined')
		{
			lz_session.UserId = window.opener.lz_get_session().UserId;
			lz_session.GeoResolved = window.opener.lz_get_session().GeoResolved;
		}
	}
	catch(ex)
	{
		// ACCESS DENIED
	}
	
	lz_session.Save();
	
	if(!lz_tracking_geo_resolute())
		lz_tracking_poll_server();
}

function lz_get_session()
{
	return lz_session;
}

function lz_tracking_server_request(_get)
{	
	if(lz_stopped)
		return;
		
	var lastScript = document.getElementById("livezilla_pollscript");
	if(lastScript == null) 
	{
		for(var index in lz_chat_windows)
			if(!lz_chat_windows[index].Deleted && lz_chat_windows[index].Closed)
			{
				lz_chat_windows[index].Deleted = true;
				_get += "&clch=" + lz_chat_windows[index].BrowserId;
			}

		_get = "?request=track&start=" + lz_global_microstamp() + _get;
		
		var newScript = document.createElement("script");
		newScript.id = "livezilla_pollscript";
		newScript.src = lz_poll_url + _get;
		lz_document_head.appendChild(newScript);
	}
}

function lz_tracking_callback(_freq)
{
	if(lz_poll_frequency != _freq)
	{
		lz_poll_frequency = _freq;
		clearTimeout(lz_timer);
		lz_timer = setTimeout("lz_tracking_poll_server();",(lz_poll_frequency*1000));
	}
	var lastScript = document.getElementById("livezilla_pollscript");
	if(lastScript != null)
		lz_document_head.removeChild(lastScript);
}

function lz_tracking_poll_server()
{
	var getValues = "&browid="+lz_session.BrowserId+"&url="+lz_global_base64_url_encode(window.location.href);
	getValues += (lz_session.UserId != null) ? "&livezilla="+ lz_session.UserId : "";
	getValues += "&cd="+window.screen.colorDepth+"&rh="+screen.height+"&rw="+screen.width+"&rf="+lz_global_base64_url_encode(lz_referrer)+"&tzo="+lz_timezone_offset;
	getValues += "&code="+lz_area_code+"&en="+lz_user_name+"&ee="+lz_user_email+"&ec="+lz_user_company+"&dc="+lz_global_base64_url_encode(document.title);
		
	if(lz_user_customs.length>0)
		for(var i=0;i<=9;i++)
			getValues += "&cf" + i + "=" + lz_user_customs[i];
		
	if(lz_geo_resolution_needed && lz_session.GeoResolved.length == 7)
		getValues += "&geo_lat=" + lz_session.GeoResolved[0] + "&geo_long=" + lz_session.GeoResolved[1] + "&geo_region=" + lz_session.GeoResolved[2] + "&geo_city=" + lz_session.GeoResolved[3] + "&geo_tz=" + lz_session.GeoResolved[4] + "&geo_ctryiso=" + lz_session.GeoResolved[5] + "&geo_isp=" + lz_session.GeoResolved[6];

	getValues += "&geo_rid=" + lz_geo_resolution.Status;
	
	if(lz_geo_resolution.Span > 0)
		getValues += "&geo_ss=" + lz_geo_resolution.Span;
		
	++lz_poll_id;
		
	if(lz_request_active != null)
		getValues += "&actreq=1";
	
	lz_tracking_server_request(getValues,true);
	
	if(!lz_stopped)
	{
		clearTimeout(lz_timer);
		lz_timer = setTimeout("lz_tracking_poll_server();",(lz_poll_frequency*1000));
	}
}

function lz_tracking_set_sessid(_userId, _browId)
{
	lz_session.UserId = _userId;
	lz_session.BrowserId = _browId;
	lz_session.Save();
}

function lz_tracking_request_chat(_reqId,_text,_template,_width,_height,_mleft,_mtop,_mright,_mbottom,_position,_speed,_slide)
{
	if(lz_request_active == null)
	{
		lz_request_active = _reqId;
		_template = lz_global_utf8_decode(lz_global_base64_decode(_template)).replace("<!--invitation_text-->",lz_global_utf8_decode(lz_global_base64_decode(_text)));
		lz_request_window = new lz_livebox("lz_request_window",_template,_width,_height,_mleft,_mtop,_mright,_mbottom,_position,_speed,_slide);
		lz_request_window.lz_livebox_show();
		window.focus();
	}
}

function lz_tracking_send_alert(_alertId,_text)
{
	if(lz_alert_active == null)
	{
		lz_alert_active = _alertId;
		lz_alert_window = new lz_livebox("lz_alert_window",lz_global_utf8_decode(lz_global_base64_decode(lz_alert_html)),350,110,0,0,0,0,11,1,0);
		lz_alert_window.lz_livebox_show();
		
		document.getElementById("lz_chat_alert_box").style.display = 'inline';
		document.getElementById("lz_chat_alert_button").onclick = function(){if(lz_alert_window != null){document.body.removeChild(document.getElementById('lz_alert_window'));lz_alert_window=null;lz_tracking_action_result("alert",true,true);lz_alert_active=null;}};
		document.getElementById("lz_chat_alert_box_text").innerHTML = lz_global_utf8_decode(lz_global_base64_decode(_text));
		window.focus();
	}
}

function lz_tracking_check_request(_reqId)
{
	if(lz_request_window == null && lz_request_active != null)
		lz_tracking_declined_request();
}

function lz_tracking_close_request()
{
	if(lz_request_active != null)
		lz_request_active = null;
		
	if(lz_request_window != null)
		lz_request_window.lz_livebox_close('lz_request_window');	
}

function lz_tracking_init_website_push(_text,_id)
{	
	if(lz_website_push_active == null)
	{
		lz_website_push_active = _id;
		var exec = confirm(lz_global_utf8_decode(lz_global_base64_decode(_text)));
		setTimeout("lz_tracking_action_result('website_push',"+exec+",true);",100);
		lz_website_push_active = null;
	}
}

function lz_tracking_exec_website_push(_url)
{	
	window.location.href = lz_global_utf8_decode(lz_global_base64_decode(_url));
}

function lz_tracking_stop_tracking()
{
	lz_stopped = true;
}

function lz_tracking_geo_result(_lat,_long,_region,_city,_tz,_ctryi2,_isp)
{	
	lz_session.GeoResolved = Array(_lat,_long,_region,_city,_tz,_ctryi2,_isp);
	lz_session.Save();
	lz_tracking_poll_server();
}

function lz_tracking_set_geo_span(_timespan)
{
	lz_geo_resolution.SetSpan(_timespan);
}

function lz_tracking_geo_resolute()
{
	if(lz_is_geo_resolution_needed())
	{
		lz_session.GeoResolutions++;
		lz_session.Save();

		lz_geo_resolution.SetStatus(1);
		if(lz_session.GeoResolutions < 4)
		{
			lz_geo_resolution.OnEndEvent = "lz_tracking_geo_result";
			lz_geo_resolution.OnSpanEvent = "lz_tracking_set_geo_span";
			lz_geo_resolution.OnTimeoutEvent = lz_tracking_geo_resolute;
			lz_geo_resolution.ResolveAsync();
		}
		else
			lz_tracking_geo_failure();
		return true;
	}
	else
	{
		lz_geo_resolution.SetStatus(7);
		return false;
	}
}

function lz_tracking_geo_failure()
{
	lz_tracking_set_geo_span(45);
	lz_geo_resolution.SetStatus(4);
	lz_session.GeoResolved = Array('LTUyMg==','LTUyMg==','','','','','');
	lz_session.Save();
	lz_tracking_poll_server();
	
}

function lz_tracking_action_result(_action,_result,_closeOnClick)
{
	var getValues = "&browid="+lz_session.BrowserId+"&url="+lz_global_base64_url_encode(window.location.href);
	getValues += (lz_session.UserId != null) ? "&livezilla="+lz_session.UserId : "";
	
	if(_action=="alert")
		getValues += "&confalert="+lz_alert_active;
	else if(_action=="chat_request" && !_result)
		getValues += "&decreq="+lz_request_active;
	else if(_action=="chat_request" && _result)
		getValues += "&accreq="+lz_request_active;
	else if(_action=="website_push" && _result)
		getValues += "&accwp="+lz_website_push_active;
	else
		getValues += "&decwp="+lz_website_push_active;
		
	if(_closeOnClick)
		getValues += "&clreq=1";

	lz_tracking_server_request(getValues);
}function lz_livebox(_name,_template,_width,_height,_mleft,_mtop,_mright,_mbottom,_position,_speed,_slide)
{
	this.lz_livebox_slide_finished = false;
	this.lz_livebox_template = _template;
	this.lz_livebox_name = _name;
	this.lz_livebox_move = lz_livebox_move_box;
	this.lz_livebox_show = lz_livebox_show_box;
	this.lz_livebox_close = lz_livebox_close_box;
	this.lz_livebox_chat = lz_livebox_direct_chat;
	this.lz_livebox_get_left = lz_livebox_center_get_left;
	this.lz_livebox_get_right = lz_livebox_center_get_right;
	this.lz_livebox_get_top = lz_livebox_center_get_top;
	this.lz_livebox_get_bottom = lz_livebox_center_get_bottom;
	
	this.lzibst_width = _width;
	this.lzibst_height = _height;
	this.lzibst_margin = new Array(_mleft,_mtop,_mright,_mbottom);
	this.lzibst_position = _position;
	this.lzibst_slide_speed = 13;
	this.lzibst_slide_disabled = !_slide;
	
	if(_speed == 2)
		this.lzibst_slide_step = 3;
	else if(_speed == 1)
		this.lzibst_slide_step = 8;
	else
		this.lzibst_slide_step = 13;
	
	function lz_livebox_direct_chat(_intid,_groupid)
	{
		var user_header = '';
		var user_email = '';
		var user_company = '';
		var area_code = '';
		var question = '';
		var custom = '';
		var user_name = '';
		
		if(document.getElementById('lz_invitation_name') != null && document.getElementById('lz_invitation_name').value.length > 0)
			user_name = lz_global_base64_url_encode(document.getElementById('lz_invitation_name').value);

		var params = "";
		if(user_header.length > 0)
			params += '&eh='+user_header;
		if(user_email.length > 0)
			params += '&ee='+user_email;
		if(user_company.length > 0)
			params += '&ec='+user_company;
		if(area_code.length > 0)
			params += '&code='+area_code;
		if(question.length > 0)
			params += '&eq='+question;
		if(custom.length > 0)
			params += custom;

		void(window.open('http://www.tmdhosting.com/chat/chat.php?intid='+_intid+'&en='+user_name+'&intgroup='+_groupid+params,'LiveZilla','width=645,height=550,left=0,top=0,resizable=yes,menubar=no,location=no,status=yes,slidebars=no'));
	}
	
	function lz_livebox_close_box(uid)
	{
		if(!this.lz_livebox_slide_finished)
			return;
		
		document.body.removeChild(this.MainDiv);
		lz_request_window = null;
	}
	
	function lz_livebox_show_box()
	{
		this.MainDiv = document.createElement('DIV');
		this.MainDiv.id = this.lz_livebox_name;
		this.MainDiv.style.position= (lz_global_is_xhtml() || !true) ? 'fixed' : 'absolute';
		this.MainDiv.style.height = this.lzibst_height+'px';
		this.MainDiv.style.width = this.lzibst_width+'px';
		this.MainDiv.style.zIndex = 1001;
		
		if(this.lzibst_position == 20 || this.lzibst_position == 21 || this.lzibst_position == 22)
			this.MainDiv.style.left = -(this.lzibst_width+100)+'px';
		else
			this.MainDiv.style.top = -(this.lzibst_height+100)+'px';
		
		this.MainDiv.innerHTML = this.lz_livebox_template.replace("<!--username-->",lz_global_base64_url_decode(""));
		document.body.appendChild(this.MainDiv);
		window.setTimeout("window['"+ this.lz_livebox_name +"'].lz_livebox_move()",1);
	}

	function lz_livebox_move_box()
	{
		this.MainDiv.style.bottom = this.lz_livebox_get_bottom();
		this.MainDiv.style.right = this.lz_livebox_get_right();

		if(this.lzibst_slide_disabled)
		{
			this.MainDiv.style.left = this.lz_livebox_get_left();
			this.MainDiv.style.top = this.lz_livebox_get_top();
			this.MainDiv.style.right = this.lz_livebox_get_right();
			this.MainDiv.style.bottom = this.lz_livebox_get_bottom();
			this.lz_livebox_slide_finished = true;
		}
		else
		{
			if(this.lzibst_position == 20 || this.lzibst_position == 21 || this.lzibst_position == 22)
			{
				var current = parseInt(this.MainDiv.style.left.replace("px","").replace("pt",""));
				current+=this.lzibst_slide_step;

				this.MainDiv.style.left = current+'px';
				this.MainDiv.style.top = this.lz_livebox_get_top();

				var leftdist = parseInt(this.lz_livebox_get_left().replace("px",""));
				if(current < (leftdist-this.lzibst_slide_step))
					window.setTimeout("window['"+ this.lz_livebox_name +"'].lz_livebox_move()",this.lzibst_slide_speed);
				else
				{
					this.MainDiv.style.left = leftdist+'px';
					this.lz_livebox_slide_finished = true;
				}
			}
			else
			{
				var current = parseInt(this.MainDiv.style.top.replace("px","").replace("pt",""));
				current+=this.lzibst_slide_step;
					
				this.MainDiv.style.top = current+'px';
				this.MainDiv.style.left = this.lz_livebox_get_left();
				
				var topdist = parseInt(this.lz_livebox_get_top().replace("px",""));
				if(current < (topdist-this.lzibst_slide_step))
					window.setTimeout("window['"+ this.lz_livebox_name +"'].lz_livebox_move()",this.lzibst_slide_speed);
				else
				{
					this.MainDiv.style.top = topdist+'px';
					this.lz_livebox_slide_finished = true;
				}
			}
		}

		if(this.lz_livebox_slide_finished && document.body.onresize == null)
		{
			if(this.MainDiv.style.position == 'absolute')
				window.onslide = lz_livebox_center_box;
			window.onresize = lz_livebox_center_box;
		}
	}
	
	function lz_livebox_center_get_left()
	{
		var left = 0;
		if(this.lzibst_position == 01 || this.lzibst_position == 11 || this.lzibst_position == 21)
		{
			left  = parseInt((true) ? (document.documentElement.offsetWidth * 50 / 100) : (window.innerWidth * 50 / 100));
			if(this.MainDiv.style.position == 'absolute')
				left += lz_global_get_page_offset_x()
			left -= parseInt(this.lzibst_width / 2);
			
			if(this.lzibst_margin[0] != 0)
				left += this.lzibst_margin[0];
			if(this.lzibst_margin[2] != 0)
				left -= this.lzibst_margin[2];
				
			return left+'px';
		}
		else if(this.lzibst_position == 00 || this.lzibst_position == 10 || this.lzibst_position == 20)
		{
			if(this.lzibst_margin[0] != 0)
				left += this.lzibst_margin[0];
			if(this.lzibst_margin[2] != 0)
				left -= this.lzibst_margin[2];
			
			left+=lz_global_get_page_offset_x();
				
			return left+'px';
		}
		else if(this.lzibst_position == 22)
		{
			left = window.innerWidth-this.lzibst_width;
			
			if(this.lzibst_margin[0] != 0)
				left += this.lzibst_margin[0];
			if(this.lzibst_margin[2] != 0)
				left -= this.lzibst_margin[2];
				
			left+=lz_global_get_page_offset_x();
				
			return left+'px';
		}
		else
			return '';
	}
	
	function lz_livebox_center_get_right()
	{
		var right = 0;
		if(this.lzibst_position == 02 || this.lzibst_position == 12 || this.lzibst_position == 22)
		{
			if(this.lzibst_margin[0] != 0)
				right -= this.lzibst_margin[0];
			if(this.lzibst_margin[2] != 0)
				right += this.lzibst_margin[2];
				
			right-=lz_global_get_page_offset_x();
				
			return right+'px';
		}
		else
			return '';
	}
	
	function lz_livebox_center_get_top()
	{
		var top = 0;
		if(this.lzibst_position == 10 || this.lzibst_position == 11 || this.lzibst_position == 12)
		{
			top  = parseInt((true) ? (document.documentElement.offsetHeight * 50 / 100) : (window.innerHeight * 50 / 100));
			if(this.MainDiv.style.position == 'absolute')
				top += lz_global_get_page_offset_y()
			top -= parseInt(this.lzibst_height / 2);
			
			if(this.lzibst_margin[1] != 0)
				top += this.lzibst_margin[1];
			if(this.lzibst_margin[3] != 0)
				top -= this.lzibst_margin[3];
				
			return parseInt(top)+'px';
		}
		else if(this.lzibst_position == 00 || this.lzibst_position == 01 || this.lzibst_position == 02)
		{
			if(this.lzibst_margin[1] != 0)
				top += this.lzibst_margin[1];
			if(this.lzibst_margin[3] != 0)
				top -= this.lzibst_margin[3];
				
			top+=lz_global_get_page_offset_y();
				
			return parseInt(top)+'px';
		}
		else
			return '';
	}
	
	function lz_livebox_center_get_bottom()
	{
		var bottom = 0;
		if(this.lzibst_position == 20 || this.lzibst_position == 21 || this.lzibst_position == 22)
		{
			if(this.lzibst_margin[1] != 0)
				bottom -= this.lzibst_margin[1];
			if(this.lzibst_margin[3] != 0)
				bottom += this.lzibst_margin[3];
			bottom-=lz_global_get_page_offset_y();
				
			return bottom+'px';
		}
		else
			return '';
	}
}

function lz_livebox_center_box()
{
	if(document.getElementById("lz_request_window") != null)
	{
		document.getElementById("lz_request_window").style.top = window['lz_request_window'].lz_livebox_get_top();
		document.getElementById("lz_request_window").style.left = window['lz_request_window'].lz_livebox_get_left();
		document.getElementById("lz_request_window").style.right = window['lz_request_window'].lz_livebox_get_right();
		document.getElementById("lz_request_window").style.bottom = window['lz_request_window'].lz_livebox_get_bottom();
	}

	if(document.getElementById("lz_alert_window") != null)
	{
		document.getElementById("lz_alert_window").style.top = window['lz_alert_window'].lz_livebox_get_top();
		document.getElementById("lz_alert_window").style.left = window['lz_alert_window'].lz_livebox_get_left();
		document.getElementById("lz_alert_window").style.right = window['lz_alert_window'].lz_livebox_get_right();
		document.getElementById("lz_alert_window").style.bottom = window['lz_alert_window'].lz_livebox_get_bottom();
	}
}